home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / icon / mclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  3.6 KB  |  158 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: mclock.c,v 4.1 88/06/21 14:00:05 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/icon/RCS/mclock.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/mclock.c,v $$Revision: 4.1 $";
  12.  
  13. /* by sdh */
  14.  
  15. #include <sys/time.h>
  16. #include <stdio.h>
  17. #include <signal.h>
  18. #include "term.h"
  19.  
  20. #define SCREEN 0
  21. #define MINS 1
  22. #define MASKMINS 13
  23. #define HRS 25
  24. #define MASKHRS 37
  25. #define FACE 49
  26. #define SCRATCH 50
  27. #define ICONPATH    "mouse"
  28.  
  29. static char *_quit = "\034";
  30.  
  31. int x, y, w, firstw, h, firsth, i, j, k;
  32. int hsize, vsize;
  33.  
  34. cleanup()
  35. {
  36.     m_clear();
  37.     m_pop();
  38.     exit(0);
  39. }
  40.  
  41. clearit()
  42. {
  43.     m_clear();
  44.     do_time();
  45. }
  46.  
  47. shapeit()
  48. {
  49.     int    border;
  50.  
  51.     get_size(&x, &y, &hsize, &vsize);
  52.     get_param( (char *)0, (int *)0, (int *)0, &border );
  53.     m_shapewindow(x, y, w + 2*border, h + 2*border);
  54. }
  55.  
  56.  
  57. main(argc,argv)
  58. char **argv;
  59. {
  60.     register int s = 0;
  61.     int speed = 1;
  62.     char buf[101];
  63.  
  64.     ckmgrterm( *argv );
  65.  
  66.     m_setup(M_FLUSH);
  67.     m_push(P_BITMAP | P_EVENT | P_FLAGS | P_POSITION);
  68.     m_setmode(M_ABS);
  69.  
  70.     if (argc>1 && strcmp(argv[1],"-s")==0)
  71.         speed++;
  72.  
  73.  
  74.     signal(SIGINT,cleanup);
  75.     signal(SIGTERM,cleanup);
  76.     signal(SIGQUIT,clearit);
  77.  
  78.     m_setevent(RESHAPE,_quit);
  79.     m_setevent(REDRAW,_quit);
  80.     
  81.     m_ttyset(); /* no echo */
  82.     fprintf(stderr,"Please wait...");
  83.     fflush(stderr);
  84.     for (i = 0; i < 12; i++) {
  85.     /* load all the hands and their masks */
  86.         sprintf(buf, "%s/mhand%d",ICONPATH, i);
  87.         m_bitfile(i+MINS, buf, &w, &h);
  88.         panic(); /* if the dimensions are wrong, panic and exit */
  89.         sprintf(buf, "%s/mmhand%d",ICONPATH, i);
  90.         m_bitfile(i+MASKMINS, buf, &w, &h);
  91.         panic();
  92.         sprintf(buf, "%s/hhand%d",ICONPATH, i);
  93.         m_bitfile(i+HRS, buf, &w, &h);
  94.         panic();
  95.         sprintf(buf, "%s/mhhand%d",ICONPATH, i);
  96.         m_bitfile(i+MASKHRS, buf, &w, &h);
  97.         panic();
  98.     }
  99.     sprintf(buf, "%s/mickface",ICONPATH); /* get the face */
  100.     m_bitfile(FACE, buf, &w, &h);
  101.     panic();
  102.     m_ttyreset();/* reset echo */
  103.     shapeit();
  104.     clearit();
  105.     while(1) {
  106.         m_flush();
  107.         do_time();
  108.         sleep(15); /* update only every 15 seconds */
  109.     }
  110. }
  111.  
  112. do_time()
  113. {
  114.     struct tm *tme, *localtime();
  115.     long tmp, time();
  116.     int hr, mn, mn1;
  117.  
  118.     tmp = time(0);
  119.     tme = localtime(&tmp); /* get the time */
  120.  
  121.     mn = tme->tm_min;
  122.     hr = (tme->tm_hour > 11 ? tme->tm_hour - 12 : tme->tm_hour);
  123.     /* set hours to be 0-11 */
  124.     mn1 = ( (mn/5) + (mn % 5 < 3 ? 0 : 1));
  125.     /* adjust minutes so that 10:03 will read as 10:05 to help accuracy */
  126.     if (mn > 33) hr++;
  127.     /* move hour hand when minute hand is on 7 so that 7:45 will look ok */
  128.     mn1 %= 12; /* fix minutes to be 0-11 */
  129.     hr %= 12; /* fix hours to be 0-11 */
  130.  
  131.     m_func(B_COPY);
  132.     m_bitcopyto(0, 0, w, h, 0, 0, SCRATCH, FACE); /* copy face */
  133.     m_func(B_AND);
  134.     m_bitcopyto(0, 0, w, h, 0, 0, SCRATCH, MASKHRS + hr); /* mask of hour */
  135.     m_func(B_OR);
  136.     m_bitcopyto(0, 0, w, h, 0, 0, SCRATCH, HRS + hr); /* OR hour in */
  137.     m_func(B_AND);
  138.     m_bitcopyto(0, 0, w, h, 0, 0, SCRATCH, MASKMINS + mn1); /* mask minutes */
  139.     m_func(B_OR);
  140.     m_bitcopyto(0, 0, w, h, 0, 0, SCRATCH, MINS + mn1); /* OR in minute hand */
  141.     m_func(B_COPY);
  142.     m_bitcopyto(0, 0, w, h, 0, 0, SCREEN, SCRATCH); /* put on screen */
  143. }
  144.  
  145. panic()
  146. {
  147.     if( !firstw )
  148.         firstw = w;
  149.     if( !firsth )
  150.         firsth = h;
  151.     if( !w  ||  !h  ||  w != firstw  ||  h != firsth ) {
  152.         m_ttyreset();
  153.         fprintf(stderr, "%d %d\n", w, h );
  154.         fprintf(stderr, "bitmap size mismatch: bitmaps may be bad.\n");
  155.         exit(0);
  156.     }
  157. }
  158.